/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SysAguas.modelo;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Heitor
 */
@Entity
@Table(name="pousada")
public class Pousada implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    @Column(name="nome")
    private String nome;

    @OneToMany(mappedBy = "pousadaT", cascade = CascadeType.ALL)
    private List<Telefone> telefonesP = new LinkedList<Telefone>();

    @OneToMany(mappedBy="pousadaR",cascade=CascadeType.MERGE)
    private List<Reserva> reservasP = new LinkedList<Reserva>();

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "id_Endereco")
    private Endereco enderecoP;

    public Pousada() {
    }

    public Endereco getEndereco() {
        return enderecoP;
    }

    public void setEndereco(Endereco endereco) {
        this.enderecoP = endereco;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public List<Reserva> getReservas() {
        return reservasP;
    }

    public void setReservas(List<Reserva> reservas) {
        this.reservasP = reservas;
    }
    public void addReserva(Reserva reserva){
        this.reservasP.add(reserva);
    }

    public List<Telefone> getTelefones() {
        return telefonesP;
    }

    public void setTelefones(List<Telefone> telefones) {
        this.telefonesP = telefones;
    }
    public void addTelefone(Telefone tel){
        this.telefonesP.add(tel);

    }
    public void removeReserva(List<Reserva> reserva){
        for (int i = 0; i < reserva.size(); i++) {
            this.reservasP.remove(reserva.get(i));

        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pousada other = (Pousada) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    

}
